package com.wwwarehouse.contract.orders;

import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.fragment.CommonBasePagerFragment;
import com.wwwarehouse.common.tools.ToastUtils;
import com.wwwarehouse.contract.bean.ImporderMonitorBean;
import com.wwwarehouse.contract.core.ContractConstant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import contract.wwwarehouse.com.contract.R;

/**
 * 订单获取监控Fragment
 * Created by ShineF on 2017/9/20 0020.
 */
@Route(path = "/contract/ImportOrdersMonitorPagerFragment")
public class ImportOrdersMonitorPagerFragmentTemp extends CommonBasePagerFragment {


    @Override
    public void setTitle() {
        if (peekFragment() instanceof ImportOrdersMonitorPagerFragmentTemp)
            mActivity.setTitle(R.string.select_shop);
    }

    @Override
    public void requestDatas() {
        super.requestDatas();
//        showConfirmButton();
//        hideSortButton();A
//        hideFilterButton();
//        showCustomBtn("提交", "取消");
        requestHttp("");
    }

    @Override
    public void onRefreshListener() {

    }

    public void requestHttp(String name) {
        Map<String, Object> map = new HashMap<>();
        map.put("type", "1");
        map.put("itemType", "H_SHOP");
        map.put("name", name);
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("page", "1");
        queryMap.put("size", "9");
        map.put("query", queryMap);
        loadData(ContractConstant.GET_IMPORT_TOOLS_MONITOR_INDEX, map, 1);
    }

    @Override
    public void onLoadSuccess(String data, int what) {
        if (1 == what) {
            ImporderMonitorBean bean = JSON.parseObject(data, ImporderMonitorBean.class);
            ArrayList<ImporderMonitorBean.ListBean> list = bean.getList();
            int total = bean.getTotal();
            Bundle bundle = new Bundle();
            bundle.putParcelableArrayList("data", bean.getList());
            try {
                setData(total, 9, "com.wwwarehouse.contract.orders.import_order.ImportOrdersMonitorPagerContentFragment", bundle, list);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void onLoadError(String errorInfo) {
        ToastUtils.showToast(errorInfo);
    }

    @Override
    public void textChanged(String text) {
        requestHttp(text);
    }
}
